# def url_get(url):
#     self.stdout.write(self.style.SUCCESS('GET %s' % (url, )))
#     return self.session.get(url)
#
# def url_gettext(url):
#     res = self.url_get(url)
#     return res.text
#
# def url_getjson(url):
#     res = self.url_get(url)
#     return res.json()

import datetime
import msgpack




class MsgPack:
    def decode_datetime(self,obj):
        if b'__datetime__' in obj:
            obj = datetime.datetime.strptime(obj["as_str"], "%Y%m%dT%H:%M:%S.%f")
        return obj

    def encode_datetime(self,obj):
        if isinstance(obj, datetime.datetime):
            return {'__datetime__': True, 'as_str': obj.strftime("%Y%m%dT%H:%M:%S.%f")}
        return obj
    @classmethod
    def dumps(cls,obj):
        return msgpack.packb(obj, default=self.encode_datetime)
    @classmethod
    def loads(cls,obj_bytes):
        return msgpack.unpackb(obj_bytes, object_hook=self.decode_datetime)
